package com.zznj.xzjc.fragment.ztgk;

import android.view.View;
import android.widget.TextView;

import com.google.gson.Gson;
import com.vondear.rxui.fragment.NewLazyFragment;
import com.zznj.xzjc.R;
import com.zznj.xzjc.bean.index.JrdwData;
import com.zznj.xzjc.net.SharedHelper;
import com.zznj.xzjc.net.entity.BaseBean;
import com.zznj.xzjc.net.entity.LoginBean;
import com.zznj.xzjc.net.rxjava.HttpMethods;
import com.zznj.xzjc.net.subscribers.ProgressSubscriber;
import com.zznj.xzjc.net.subscribers.SubscriberOnNextListener;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import okhttp3.FormBody;

/**
 * 描述：知识库
 */
public class JrdwFragment extends NewLazyFragment {
    @BindView(R.id.gajgNum)
    TextView gajgNum;
    @BindView(R.id.jcjgNum)
    TextView jcjgNum;
    @BindView(R.id.fyNum)
    TextView fyNum;

    @BindView(R.id.xzjgNum)
    TextView xzjgNum;
    @BindView(R.id.sjxzNum)
    TextView sjxzNum;
    @BindView(R.id.xjxzNum)
    TextView xjxzNum;

    Unbinder unbinder;
    private boolean isShowDialog = true;


    public static JrdwFragment getInstance() {
        JrdwFragment fragment = new JrdwFragment();
        return fragment;
    }

    @Override
    protected int getContentViewId() {
        return R.layout.gyss_fragment_ztgk_jrdw__layout;
    }

    private LoginBean user;

    @Override
    protected void initView(View view) {
        unbinder = ButterKnife.bind(this, view);
        user = new Gson().fromJson(SharedHelper.readValueByKeyForString(mContext, "Member"), LoginBean.class);
        super.initView(view);
    }

    @Override
    protected void initData() {
    }

    @Override
    public void onResume() {
        super.onResume();
        getData();
    }

    private void getData() {
        SubscriberOnNextListener<BaseBean<JrdwData>> onNextListener = baseBean -> {
            gajgNum.setText(baseBean.getResult().getPoliceNum()+"");
            jcjgNum.setText(baseBean.getResult().getJianChaNum()+"");
            fyNum.setText(baseBean.getResult().getJudgeNum()+"");

            xzjgNum.setText(baseBean.getResult().getXingZhengNum() + "");
            sjxzNum.setText(baseBean.getResult().getCityXingZhengNum() + "");
            xjxzNum.setText(baseBean.getResult().getCountyXingZhengNum() + "");
        };
        FormBody requestBody = new FormBody.Builder()
                .add("districtJB", "")
                .build();
        HttpMethods.getInstance().jierudanweiData(new ProgressSubscriber<>(onNextListener, mContext, true), requestBody);
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
        unbinder.unbind();
    }
}